<template>
  <div class="app-container">
    <el-card class="box-card">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
      <el-form-item label="公告标题" prop="noticeTitle">
        <el-input
          v-model="queryParams.noticeTitle"
          placeholder="请输入公告标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户浏览次数" prop="userViewsCounts">
        <el-input
          v-model="queryParams.userViewsCounts"
          placeholder="请输入用户浏览次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <br/>
      <div style="text-align:right;">

        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>

      </div>
      <br/>
    </el-form>
    <el-table v-loading="loading" :data="statisticsList" border @selection-change="handleSelectionChange">
      <el-table-column type="index" label="序号" width="55" :index="indexMethod" align="center" />
      <el-table-column label="公告标题"   align="center" prop="noticeTitle" />
      <el-table-column label="用户名" width="300" align="center" prop="username" />
      <el-table-column label="用户浏览次数" width="300" align="center" prop="userViewsCounts" />
      <el-table-column label="浏览时间"  align="center" prop="viewsTimes"  width="300" >
        <template slot-scope="scope">
           <p>{{ c12(scope.row.viewsTimes)}}
           </p>
        </template>
      </el-table-column>>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
  </div>
</template>
<script>
import { listStatistics, getStatistics } from "@/api/module/yzx/cs/statistics";
import watermark from "watermark-dom";
export default {
  name: "Statistics",
  mounted() {
    watermark.load({ watermark_txt: '  '   });
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告浏览统计表格数据
      statisticsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeId: null,
        noticeTitle: null,
        userViewsCounts: null,
        deptViewsCounts: null,
        startViewsTimes: null,
        endViewsTimes: null,
        viewsTimes: null,
        userId: null,
        deptId: null,
        username: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
      c12 (m) {
        let c1 = m.substr(0,3);
        let c2 = m.substr(3,2);
        let company =c1+"小时"+c2+"分钟";
        return company
      },
    indexMethod(index) {
      index = (index + 1) + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
      return index
    },
/** 查询公告浏览统计列表 */
    getList() {
      this.loading = true;
      listStatistics(this.queryParams).then(response => {
        this.statisticsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        noticeId: null,
        noticeTitle: null,
        userViewsCounts: null,
        deptViewsCounts: null,
        startViewsTimes: null,
        endViewsTimes: null,
        viewsTimes: null,
        userId: null,
        deptId: null,
        username: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加公告浏览统计";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStatistics(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改公告浏览统计";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStatistics(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStatistics(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除公告浏览统计编号为"' + ids + '"的数据项？').then(function() {
        return delStatistics(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>
